package cn.com.guage.dtm.stat.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.com.guage.dtm.common.annotation.Log;
import cn.com.guage.dtm.common.enums.BusinessType;
import cn.com.guage.dtm.stat.domain.StatTransReport;
import cn.com.guage.dtm.stat.service.IStatTransReportService;
import cn.com.guage.dtm.common.core.controller.BaseController;
import cn.com.guage.dtm.common.core.domain.AjaxResult;
import cn.com.guage.dtm.common.utils.poi.ExcelUtil;
import cn.com.guage.dtm.common.core.page.TableDataInfo;

/**
 * 数据迁移报告Controller
 * 
 * @author yangdechao
 * @date 2021-06-22
 */
@Controller
@RequestMapping("/stat/report")
public class StatTransReportController extends BaseController
{
    private String prefix = "stat/report";

    @Autowired
    private IStatTransReportService statTransReportService;

    @RequiresPermissions("stat:report:view")
    @GetMapping()
    public String report()
    {
        return prefix + "/report";
    }

    /**
     * 查询数据迁移报告列表
     */
    @RequiresPermissions("stat:report:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StatTransReport statTransReport)
    {
        startPage();
        List<StatTransReport> list = statTransReportService.selectStatTransReportList(statTransReport);
        return getDataTable(list);
    }

    /**
     * 导出数据迁移报告列表
     */
    @RequiresPermissions("stat:report:export")
    @Log(title = "数据迁移报告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StatTransReport statTransReport)
    {
        List<StatTransReport> list = statTransReportService.selectStatTransReportList(statTransReport);
        ExcelUtil<StatTransReport> util = new ExcelUtil<StatTransReport>(StatTransReport.class);
        return util.exportExcel(list, "数据迁移报告数据");
    }

    /**
     * 新增数据迁移报告
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存数据迁移报告
     */
    @RequiresPermissions("stat:report:add")
    @Log(title = "数据迁移报告", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StatTransReport statTransReport)
    {
        return toAjax(statTransReportService.insertStatTransReport(statTransReport));
    }

    /**
     * 修改数据迁移报告
     */
    @GetMapping("/edit/{transReportId}")
    public String edit(@PathVariable("transReportId") Long transReportId, ModelMap mmap)
    {
        StatTransReport statTransReport = statTransReportService.selectStatTransReportById(transReportId);
        mmap.put("statTransReport", statTransReport);
        return prefix + "/edit";
    }

    /**
     * 修改保存数据迁移报告
     */
    @RequiresPermissions("stat:report:edit")
    @Log(title = "数据迁移报告", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StatTransReport statTransReport)
    {
        return toAjax(statTransReportService.updateStatTransReport(statTransReport));
    }

    /**
     * 删除数据迁移报告
     */
    @RequiresPermissions("stat:report:remove")
    @Log(title = "数据迁移报告", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(statTransReportService.deleteStatTransReportByIds(ids));
    }
    
    @RequiresPermissions("stat:report:showStatTransReportDetailPage")
   	@GetMapping("/showStatTransReportDetailPage/{transReportId}")
   	public String showStatTransReportDetailPage(@PathVariable("transReportId") Long transReportId, ModelMap mmap) {
   		mmap.put("transReportId", transReportId);
   		return prefix + "/report_detail-table-list";
   	}
}
